package cn.stylefeng.guns.modular.transport.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.transport.entity.TransportReceipt;
import cn.stylefeng.guns.modular.transport.mapper.TransportReceiptMapper;
import cn.stylefeng.guns.modular.transport.model.params.TransportReceiptParam;
import cn.stylefeng.guns.modular.transport.model.result.TDispatchResult;
import cn.stylefeng.guns.modular.transport.model.result.TransportReceiptResult;
import  cn.stylefeng.guns.modular.transport.service.TransportReceiptService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 回传单表 服务实现类
 */
@Service
public class TransportReceiptServiceImpl extends ServiceImpl<TransportReceiptMapper, TransportReceipt> implements TransportReceiptService {

    @Override
    public void add(TransportReceiptParam param){
        TransportReceipt entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TransportReceiptParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TransportReceiptParam param){
        TransportReceipt oldEntity = getOldEntity(param);
        TransportReceipt newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TransportReceiptResult findBySpec(TransportReceiptParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<TransportReceiptResult> findListBySpec(TransportReceiptParam param,Long operateId){
        return this.baseMapper.findListBySpec(param,operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(TransportReceiptParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findTransportSetPageBySpec(TransportReceiptParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findTransportSetPageBySpec(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TransportReceiptParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TransportReceipt getOldEntity(TransportReceiptParam param) {
        return this.getById(getKey(param));
    }

    private TransportReceipt getEntity(TransportReceiptParam param) {
        TransportReceipt entity = new TransportReceipt();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public void deleteBySpec(TransportReceiptParam param) {
		this.baseMapper.deleteBySpec(param);
	}

	@Override
	public TransportReceiptResult sumBySpec(TransportReceiptParam param) {
		return this.baseMapper.sumBySpec(param);
	}

    @Override
    public List<TransportReceiptResult> findbyCarnum(String privatecarCarnumber) {
        return this.baseMapper.findbyCarnum(privatecarCarnumber);
    }

	@Override
	public List<TransportReceiptResult> findchengyunshangMingxiCount(TransportReceiptParam transportReceiptParam,
			String condition, String driver1, String money) {
		return this.baseMapper.findchengyunshangMingxiCount(transportReceiptParam, condition,driver1,money);
	}

	@Override
	public void updateBySpec(TransportReceiptParam transportReceiptParam) {
		this.baseMapper.updateBySpec(transportReceiptParam);
	}

	@Override
	public TransportReceiptResult getPrintReceipt(TransportReceiptParam transportReceiptParam) {
		return this.baseMapper.getPrintReceipt(transportReceiptParam);
	}

	@Override
	public List<TransportReceiptResult> findtransportSetListBySpec(TransportReceiptParam transportReceiptParam) {
		return this.baseMapper.findtransportSetListBySpec(transportReceiptParam);
	}

	@Override
	public List<TransportReceiptResult> findzcsxListBySpec(TransportReceiptParam transportReceiptParamzcsx) {
		return this.baseMapper.findzcsxListBySpec(transportReceiptParamzcsx);
	}

	@Override
	public List<TransportReceiptResult> findfenceListBySpec(TransportReceiptParam transportReceiptParam) {
		return this.baseMapper.findfenceListBySpec(transportReceiptParam);
	}

	@Override
	public Integer countcheckzhixing(String dispatchNumber) {
		return this.baseMapper.countcheckzhixing(dispatchNumber);
	}

	@Override
	public void updatePrint(TransportReceiptParam transportReceiptParam) {
		this.baseMapper.updatePrint(transportReceiptParam);
	}

}
